//
//  Character+extension.swift
//  iUtil
//
//  Created by wdc on 2019/5/2.
//  Copyright © 2019 wendachuan. All rights reserved.
//

import UIKit

/// Character扩展
public extension Character {
    
    /// 获得字符的整型值
    ///
    /// - Returns:
    func intValue() -> Int {
        var intFromCharacter:Int = 0
        for scalar in String(self).unicodeScalars {
            intFromCharacter = Int(scalar.value)
        }
        return intFromCharacter
    }
    
    /// 从整型值创建字符
    ///
    /// - Parameter integer:
    /// - Returns: 
    static func fromInt(integer: Int) -> Character? {
        if let scalar = UnicodeScalar(integer) {
            return Character(scalar)
        } else {
            return nil
        }
    }
}
